package com.thread.threadfirst.arithmetic;

import org.apache.commons.lang3.ArrayUtils;

/**
 * 冒泡排序
 */
public class MaoPao {

    public void sort(int[] a) {
        for (int i = 0; i < a.length; i++) {
            for (int j = 0; j < a.length - i - 1; j++) {
                if (a[j] > a[j + 1]) {
                    int z = a[j];
                    a[j] = a[j + 1];
                    a[j + 1] = z;
                }
            }
        }
    }

    public static void main(String[] args) {
        int[] arr = {2, 9, 5, 3, 1};
        MaoPao mp = new MaoPao();
        mp.sort(arr);
        String str = ArrayUtils.toString(arr);
        System.out.println(str);
    }

}
